﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WinformTest
{
    class DbHelp
    {
        public static readonly string conString = "server=.;datatest=bbtest;uid=xiaoyou;pwd=123456";


        public static DataTable GetDataTable(string sql)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql,sqlConnection);
            DataTable dt = new DataTable();
            sqlConnection.Open();
            dataAdapter.Fill(dt);
            return dt;
        }

        public static SqlDataReader Query(string cmdString)
        {
            SqlConnection sqlConnection = new SqlConnection(conString);
            SqlCommand command = new SqlCommand(cmdString, sqlConnection);
            sqlConnection.Open();
            SqlDataReader reader = command.ExecuteReader();
            reader.Read();
            return reader;
        }


    }
}
